using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Interactor_ForceBubble_Ctrl : Unit_Interactor_Ctrl
{
    public Transform targetPoint;
    public ParabolaData parabolaData;
    void Start()
    {
        
    }
    private void OnDrawGizmos()
    {
        if (targetPoint != null)
        {
            List<Vector3> linePoss = parabolaData.GetLinePoints(this.transform.position, targetPoint.transform.position);
            for (int i = 1; i < linePoss.Count; i++)
            {
                Gizmos.DrawLine(linePoss[i - 1], linePoss[i]);
            }
        }

    }
    public override void ReceiveLight(Vector3 sourcePos, Vector3 sourceDirection)
    {
        base.receiveLightEvent?.Invoke(sourcePos, sourceDirection);
    }
    // Update is called once per frame
    void Update()
    {

    }
    protected override void OnUnitTriggerEnter(Unit_Base unit_Base)
    {
        if (!innerUnits.Contains(unit_Base))
        {
            switch (unit_Base.unitType)
            {
                case UnitType.Charactor:
                    Unit_Charactor_Ctrl unit_Charactor_Ctrl = (Unit_Charactor_Ctrl)unit_Base;
                    unit_Charactor_Ctrl.virtualGravityVelocity = (targetPoint.transform.position - this.transform.position).normalized * parabolaData.initVelocity;
                    break;
            }
        }
        base.OnUnitTriggerEnter(unit_Base);


    }
    protected override void OnUnitTriggerExit(Unit_Base unit_Base)
    {
        if (innerUnits.Contains(unit_Base))
        {
            switch (unit_Base.unitType)
            {
                case UnitType.Charactor:
                    Unit_Charactor_Ctrl unit_Charactor_Ctrl = (Unit_Charactor_Ctrl)unit_Base;
                    Vector3 direction = (targetPoint.transform.position - this.transform.position).normalized * parabolaData.initVelocity;
                    unit_Charactor_Ctrl.rigibody.velocity = new Vector2(unit_Charactor_Ctrl.rigibody.velocity.x, direction.y);
                   // unit_Charactor_Ctrl._otherVelocity -= direction;
                    break;
            }
        }
        base.OnUnitTriggerExit(unit_Base);
    }

}
